package com.zhanyf.heilan.cg.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhanyf.heilan.cg.domain.DevelopProgress;
import com.zhanyf.heilan.cg.exception.DaoException;
import com.zhanyf.heilan.cg.service.DevelopTypeService;
import com.zhanyf.heilan.cg.util.ConstantUtil;

@Controller
@RequestMapping("/developProgress")
public class DevelopProgressController {

	@Autowired
	private DevelopTypeService developTypeService;

	@RequestMapping("/view")
	public String view() {
		return "developProgress/view";
	}

	/**
	 * 添加开发进度页面
	 * 
	 * @return
	 */
	@RequestMapping("/addDevelopProgressView")
	public String addDevelopProgressView() {
		return "developProgress/addDevelopProgressView";
	}

	/**
	 * 添加开发类型
	 * 
	 * @param typeName
	 * @return
	 */
	@RequestMapping("/addDevelopType")
	@ResponseBody
	public Map<String, Object> addDevelopType(String typeName) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			developTypeService.addDevelopType(typeName);
			map.put(ConstantUtil.SUCCESS, true);
		} catch (DaoException e) {
			map.put(ConstantUtil.SUCCESS, false);
			map.put(ConstantUtil.MSG, e.getMessage());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 查询开发类型
	 * 
	 * @return
	 */
	@RequestMapping("/listDevelopTypes")
	@ResponseBody
	public Map<String, Object> listDevelopTypes() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(ConstantUtil.DATA, developTypeService.listDevelopTypes());
		return map;
	}

	/**
	 * 查询开发进度
	 * 
	 * @param typeName
	 * @return
	 */
	@RequestMapping("/listDevelopProgressByDevelopType")
	@ResponseBody
	public Map<String, Object> listDevelopProgressByDevelopType(int developTypeId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(ConstantUtil.DATA, developTypeService.listDevelopProgressByDevelopType(developTypeId));
		return map;
	}

	/**
	 * 添加开发进度
	 * 
	 * @param typeName
	 * @return
	 */
	@RequestMapping("/addDevelopProgress")
	@ResponseBody
	public Map<String, Object> addDevelopProgress(DevelopProgress developProgress) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			developTypeService.addDevelopProgress(developProgress);
			map.put(ConstantUtil.SUCCESS, true);
		} catch (DaoException e) {
			map.put(ConstantUtil.SUCCESS, false);
			map.put(ConstantUtil.MSG, e.getMessage());
			e.printStackTrace();
		}
		return map;
	}

}
